package cl.golive.d2menu.pantallas;

import cl.golive.d2menu.obj.Plato;
import cl.golive.d2menu.utils.tableUtils.AccionesTablaUtil;
import javax.swing.JTable;
import uk.org.retep.swing.glass.FadingDialog;

/**
 *
 * @author whyem
 */
public class PantallaVerPlato extends FadingDialog{

    private java.awt.Frame parent;
    private Plato plato = new Plato();
    private String rutaImagen = "/resources/imagenesPlatos";

    /** Creates new form pantallaVerPlato */
    public PantallaVerPlato(java.awt.Frame _parent, boolean modal, Plato _plato) {
        super(_parent, modal);
        this.parent = _parent;
        this.plato = _plato;
        initComponents();
        initComponentesPersonalizados();
        cargarPlato();
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">
    private void initComponents() {

        jPanel1 = new javax.swing.JPanel();
        pnlBotones = new javax.swing.JPanel();
        botoneraAcciones = new javax.swing.JToolBar();
        botonAgregar = new javax.swing.JButton();
        botonVolver = new javax.swing.JButton();
        jPanel3 = new javax.swing.JPanel();
        pnlTitulo = new javax.swing.JPanel();
        lblNombrePlato = new javax.swing.JLabel();
        lblPrecio = new javax.swing.JLabel();
        pnlCentral = new javax.swing.JPanel();
        jSeparator5 = new javax.swing.JSeparator();
        pnlImagen = new javax.swing.JPanel();
        lblImagen = new javax.swing.JLabel();
        pnlDescripcion = new javax.swing.JPanel();
        jSeparator4 = new javax.swing.JSeparator();
        jScrollPane1 = new javax.swing.JScrollPane();
        txtpnDescripcion = new javax.swing.JEditorPane();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        setModal(true);
        setUndecorated(true);

        jPanel1.setBackground(new java.awt.Color(0, 0, 0));
        jPanel1.setLayout(new java.awt.BorderLayout());

        pnlBotones.setBackground(new java.awt.Color(0, 0, 0));
        pnlBotones.setBorder(javax.swing.BorderFactory.createTitledBorder(""));
        pnlBotones.setLayout(new java.awt.BorderLayout());

        botoneraAcciones.setBackground(new java.awt.Color(0, 0, 0));
        botoneraAcciones.setFloatable(false);
        botoneraAcciones.setOrientation(1);
        botoneraAcciones.setRollover(true);

        botonAgregar.setBackground(new java.awt.Color(0, 0, 0));
        botonAgregar.setForeground(new java.awt.Color(255, 255, 255));
        botonAgregar.setIcon(new javax.swing.ImageIcon(getClass().getResource("/resources/imagenesApp/B_agregar.png"))); // NOI18N
        botonAgregar.setText("Agregar al pedido");
        botonAgregar.setFocusable(false);
        botonAgregar.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        botonAgregar.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        botonAgregar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                botonAgregarActionPerformed(evt);
            }
        });
        botoneraAcciones.add(botonAgregar);

        botonVolver.setBackground(new java.awt.Color(0, 0, 0));
        botonVolver.setForeground(new java.awt.Color(255, 255, 255));
        botonVolver.setIcon(new javax.swing.ImageIcon(getClass().getResource("/resources/imagenesApp/B_volver.png"))); // NOI18N
        botonVolver.setText("Volver");
        botonVolver.setFocusable(false);
        botonVolver.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        botonVolver.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        botonVolver.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                botonVolverActionPerformed(evt);
            }
        });
        botoneraAcciones.add(botonVolver);

        pnlBotones.add(botoneraAcciones, java.awt.BorderLayout.CENTER);

        jPanel1.add(pnlBotones, java.awt.BorderLayout.LINE_END);

        jPanel3.setBackground(new java.awt.Color(0, 0, 0));
        jPanel3.setBorder(javax.swing.BorderFactory.createTitledBorder(""));
        jPanel3.setLayout(new java.awt.BorderLayout());

        pnlTitulo.setBackground(new java.awt.Color(0, 0, 0));
        pnlTitulo.setBorder(new javax.swing.border.SoftBevelBorder(javax.swing.border.BevelBorder.RAISED));
        pnlTitulo.setPreferredSize(new java.awt.Dimension(362, 80));
        pnlTitulo.setLayout(new java.awt.GridLayout(1, 2));

        lblNombrePlato.setFont(new java.awt.Font("Harabara", 1, 30)); // NOI18N
        lblNombrePlato.setForeground(new java.awt.Color(255, 255, 255));
        lblNombrePlato.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        lblNombrePlato.setText("Nombre Plato");
        pnlTitulo.add(lblNombrePlato);

        lblPrecio.setFont(new java.awt.Font("Harabara", 1, 30)); // NOI18N
        lblPrecio.setForeground(new java.awt.Color(255, 255, 255));
        lblPrecio.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        lblPrecio.setText("Precio");
        pnlTitulo.add(lblPrecio);

        jPanel3.add(pnlTitulo, java.awt.BorderLayout.PAGE_START);

        pnlCentral.setLayout(new java.awt.BorderLayout());
        pnlCentral.add(jSeparator5, java.awt.BorderLayout.PAGE_START);

        pnlImagen.setPreferredSize(new java.awt.Dimension(600, 400));
        pnlImagen.setLayout(new java.awt.GridLayout(1, 0));

        lblImagen.setBackground(new java.awt.Color(0, 0, 0));
        lblImagen.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        lblImagen.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        lblImagen.setOpaque(true);
        pnlImagen.add(lblImagen);

        pnlCentral.add(pnlImagen, java.awt.BorderLayout.CENTER);

        jPanel3.add(pnlCentral, java.awt.BorderLayout.CENTER);

        pnlDescripcion.setBackground(new java.awt.Color(0, 0, 0));
        pnlDescripcion.setPreferredSize(new java.awt.Dimension(456, 200));
        pnlDescripcion.setLayout(new java.awt.BorderLayout());
        pnlDescripcion.add(jSeparator4, java.awt.BorderLayout.NORTH);

        jScrollPane1.setBorder(null);

        txtpnDescripcion.setBackground(new java.awt.Color(0, 0, 0));
        txtpnDescripcion.setBorder(null);
        txtpnDescripcion.setContentType("text/html");
        txtpnDescripcion.setEditable(false);
        txtpnDescripcion.setFont(new java.awt.Font("Narkisim", 1, 18)); // NOI18N
        txtpnDescripcion.setForeground(new java.awt.Color(255, 255, 255));
        jScrollPane1.setViewportView(txtpnDescripcion);

        pnlDescripcion.add(jScrollPane1, java.awt.BorderLayout.CENTER);

        jPanel3.add(pnlDescripcion, java.awt.BorderLayout.PAGE_END);

        jPanel1.add(jPanel3, java.awt.BorderLayout.CENTER);

        getContentPane().add(jPanel1, java.awt.BorderLayout.CENTER);

        pack();
    }// </editor-fold>

    private void botonVolverActionPerformed(java.awt.event.ActionEvent evt) {
        this.setVisible(false);
        this.dispose();
    }

    private void botonAgregarActionPerformed(java.awt.event.ActionEvent evt) {
        try {
            JTable grillaCompra = ((PantallaPrincipalDedos) this.parent).getGrillaCompra();
            AccionesTablaUtil.agregarPlatoAListaPedido(grillaCompra, plato);
        }catch(Exception ex) {
            System.out.println("> Error de casting: "+ex.getMessage());
        }finally {
            this.setVisible(false);
            this.dispose();
        }
    }

    /**
    * @param args the command line arguments
    */
    public static void main(String args[]) {
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                PantallaVerPlato_ dialog = new PantallaVerPlato_(new javax.swing.JFrame(), true, new Plato());
                dialog.addWindowListener(new java.awt.event.WindowAdapter() {
                    public void windowClosing(java.awt.event.WindowEvent e) {
                        System.exit(0);
                    }
                });
                dialog.setVisible(true);
            }
        });
    }

    private void initComponentesPersonalizados() {
        this.setSize(960,780);
        this.setLocationRelativeTo(null);
    }

    private void cargarPlato() {
        lblNombrePlato.setText(plato.getNombrePlato());
        lblImagen.setIcon(new javax.swing.ImageIcon(getClass().getResource(rutaImagen+"/"+plato.getCategoriaId()+"/"+plato.getNombreImagen()+".jpg")));
        lblPrecio.setText("$ "+plato.getPrecio());

        StringBuilder textoDetalle = new StringBuilder();
        textoDetalle.append("<html><font size='5' face='trebuchet ms' color='white'>");
        textoDetalle.append(plato.getDetallePlato());
        textoDetalle.append("</font></html>");

        txtpnDescripcion.setText(textoDetalle.toString());
    }

    // Variables declaration - do not modify
    private javax.swing.JButton botonAgregar;
    private javax.swing.JButton botonVolver;
    private javax.swing.JToolBar botoneraAcciones;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel3;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JSeparator jSeparator4;
    private javax.swing.JSeparator jSeparator5;
    private javax.swing.JLabel lblImagen;
    private javax.swing.JLabel lblNombrePlato;
    private javax.swing.JLabel lblPrecio;
    private javax.swing.JPanel pnlBotones;
    private javax.swing.JPanel pnlCentral;
    private javax.swing.JPanel pnlDescripcion;
    private javax.swing.JPanel pnlImagen;
    private javax.swing.JPanel pnlTitulo;
    private javax.swing.JEditorPane txtpnDescripcion;
    // End of variables declaration

}
